package com.ruoyi.web.controller.erpbase;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.WeightConfig;
import com.ruoyi.system.service.IWeightConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 地磅配置Controller
 * 
 * @author he
 * @date 2025-09-22
 */
@Api(tags = "地磅配置接口")
@RestController
@RequestMapping("/system/weightConfig")
public class WeightConfigController extends BaseController
{
    @Autowired
    private IWeightConfigService weightConfigService;

    /**
     * 查询地磅配置列表
     */
    @ApiOperation("查询地磅配置信息")
    @PreAuthorize("@ss.hasPermi('system:weightConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(WeightConfig weightConfig)
    {
        startPage();
        List<WeightConfig> list = weightConfigService.selectWeightConfigList(weightConfig);
        return getDataTable(list);
    }

    /**
     * 导出地磅配置列表
     */
    @ApiOperation("导出地磅信息")
    @PreAuthorize("@ss.hasPermi('system:weightConfig:export')")
    @Log(title = "地磅配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WeightConfig weightConfig)
    {
        List<WeightConfig> list = weightConfigService.selectWeightConfigList(weightConfig);
        ExcelUtil<WeightConfig> util = new ExcelUtil<WeightConfig>(WeightConfig.class);
        util.exportExcel(response, list, "地磅配置数据");
    }

    /**
     * 获取地磅配置详细信息
     */
    @ApiOperation("查询地磅详细信息")
    @PreAuthorize("@ss.hasPermi('system:weightConfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(weightConfigService.selectWeightConfigById(id));
    }

    /**
     * 新增地磅配置
     */
    @ApiOperation("新增地磅信息")
    @PreAuthorize("@ss.hasPermi('system:weightConfig:add')")
    @Log(title = "地磅配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WeightConfig weightConfig)
    {
        return toAjax(weightConfigService.insertWeightConfig(weightConfig));
    }

    /**
     * 修改地磅配置
     */
    @ApiOperation("修改地磅信息")
    @PreAuthorize("@ss.hasPermi('system:weightConfig:edit')")
    @Log(title = "地磅配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WeightConfig weightConfig)
    {
        return toAjax(weightConfigService.updateWeightConfig(weightConfig));
    }

    /**
     * 删除地磅配置
     */
    @ApiOperation("删除地磅信息")
    @PreAuthorize("@ss.hasPermi('system:weightConfig:remove')")
    @Log(title = "地磅配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(weightConfigService.deleteWeightConfigByIds(ids));
    }
}
